//
//  ChatModel.m
//  MQTT-Demo
//
//  Created by zhaoguoteng on 2020/4/11.
//  Copyright © 2020 zhaoguoteng. All rights reserved.
//

#import "ChatModel.h"

@implementation ChatBodyModel

+ (nullable NSDictionary<NSString *, id> *)modelContainerPropertyGenericClass {
    return @{
        @"body": ChatModel.class
    };
}

@end

@implementation ChatModel

- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
    ChatTypeEnum type = dic[@"type"];
    
    if ([type isEqualToString: kChatTypeEnumText]) {
        self.content = [ChatTextModel yy_modelWithDictionary:dic[@"content"]];
    } else if ([type isEqualToString: kChatTypeEnumImage]) {
        self.content = [ChatImgModel yy_modelWithDictionary:dic[@"content"]];
    }
    
    return YES;
}

@end

@implementation ChatTextModel

+ (ChatBodyModel *)body:(NSString *)text {
    ChatBodyModel *body = [[ChatBodyModel alloc] init];
    
    ChatModel *chatModel = [[ChatModel alloc] init];
    
    ChatTextModel *textModel = [[ChatTextModel alloc] init];
    textModel.text = text;
    
    chatModel.type = kChatTypeEnumText;
    chatModel.content = textModel;
    
    body.body = @[chatModel];
    return body;
}

@end

@implementation ChatImgModel

@end
